package com.mtzqc.common.ui.activity

import android.graphics.Color
import android.os.Bundle
import android.view.View
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar
import com.kingja.loadsir.core.LoadService
import com.mtzqc.common.loadsir.PageStateView

abstract class SupportActivity : CommonActivity(), PageStateView {
    var loadServiceImpl: LoadService<Any>? = null
    override var loadService: LoadService<Any>?
        get() = loadServiceImpl
        set(value) {
            loadServiceImpl = value
        }

    override fun initContentView(savedInstanceState: Bundle?) {
        setContentView()
        //开始业务逻辑
        initView(savedInstanceState)
    }

    abstract fun setContentView()

    open fun initTitleBarView(view: View?) {
        //设置沉浸式
        initImmersionBar(titleBarView(view))
    }

   open fun titleBarView(view: View?): View? {
        return null
    }


    open fun initView(savedInstanceState: Bundle?) {
    }

    open fun initImmersionBar(tb: View?) {
        buildImmersionBar(tb)?.init()
    }

    open fun useTranslucentQmui(): Boolean {
        return false
    }

    open fun fullScreenEnable(): Boolean {
        return false
    }

    open fun isNightMode(): Boolean {
        return false
    }

    open fun keyboardEnable(): Boolean {
        return false
    }

    open fun hideNavigationBar(): Boolean {
        return false
    }

    open fun buildImmersionBar(tb: View?): ImmersionBar? {
        val immersionBar = ImmersionBar.with(this)
        if (fullScreenEnable()) {
            immersionBar.hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)
        } else if (hideNavigationBar()) {
            immersionBar.keyboardEnable(keyboardEnable())
        }
        immersionBar.titleBar(tb)
            .statusBarDarkFont(isNightMode())//状态栏字体默认为亮色，设置为深色
            .navigationBarColorInt(Color.WHITE)//导航栏默认为黑色，设置为白色
            .navigationBarDarkIcon(isNightMode())//导航栏默认为亮色，设置为深色
        if (hideNavigationBar()) {
            immersionBar.transparentNavigationBar()
        }
        return immersionBar
    }


}